import gi

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk

xml = """\
<interface>
  <template class="example3" parent="GtkBox">
    <child>
      <object class="ExampleButton" id="hello_button">
        <property name="label">Hello World</property>
        <signal name="clicked" handler="hello_button_clicked" swapped="no" />
      </object>
    </child>
  </template>
</interface>
"""


class HelloButton(Gtk.Button):
    __gtype_name__ = "ExampleButton"


@Gtk.Template(string=xml)
class Foo(Gtk.Box):
    __gtype_name__ = "example3"

    hello_button = Gtk.Template.Child()

    @Gtk.Template.Callback()
    def hello_button_clicked(self, *args):
        pass
class MyWindow(Gtk.Window):
    def __init__(self):
        super().__init__(title="Hello World")

        self.foo = Foo()
        self.foo.hello_button.connect("clicked", self.on_button_clicked)
        self.add(self.foo)

    def on_button_clicked(self, widget):
        print("Hello World")


win = MyWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()